home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / c / tox.lha / tox / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-23  |  2.1 KB  |  88 lines

  1. /*-------------------------------------------------------------------------
  2.  * tox - an XML tokenizer
  3.  *
  4.  * Copyright (c) 2000 Eckhart Köppen
  5.  *
  6.  * This library is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Library General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * This library is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the GNU
  14.  * Library General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Library General Public
  17.  * License along with this library; if not, write to the
  18.  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19.  * Boston, MA 02111-1307, USA.
  20.  *-----------------------------------------------------------------------*/
  21.  
  22. /* $Id: main.c,v 1.9 2000/05/19 14:29:12 koeppen Exp $ */
  23.  
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include "tox.h"
  27.  
  28. void element_callback (parser_state *);
  29. void word_callback (parser_state *);
  30. void ws_callback (parser_state *);
  31.  
  32. void element_callback (parser_state *parser)
  33. {
  34.     printf ("[%s]", parser->buffer);
  35. }
  36.  
  37. void word_callback (parser_state *parser)
  38. {
  39.     printf ("%s", parser->buffer);
  40. }
  41.  
  42. void ws_callback (parser_state *parser)
  43. {
  44.     printf ("%s", parser->buffer);
  45. }
  46.  
  47. int main (int argc, char *argv[])
  48. {
  49.     FILE *f;
  50.     parser_state parser;
  51.     char_t buffer[128];
  52.     int n;
  53.     char_t localtext[100];
  54.  
  55.     memset (&parser, 0, sizeof (parser_state));
  56.     parser.text = localtext;
  57.     
  58.     parser.state = STATE_CONTENT;
  59.  
  60.     parser.buffer = buffer;
  61.     parser.maxbuf = 127;
  62.     parser.pump = 0;
  63.     parser.bcurrent = 0;
  64.  
  65.     parser.element_callback = element_callback;
  66.     parser.word_callback = word_callback;
  67.     parser.ws_callback = ws_callback;
  68.  
  69.     while (!feof (stdin) && parser.state != STATE_ERROR) {
  70.         n = fread (localtext, 1, 1, stdin);
  71.         localtext[n] = '\0';
  72.  
  73.         parser.current = 0;
  74.         parser.maxtext = n;
  75.  
  76.         tox_parse (&parser);
  77.     }
  78.     printf ("%d %s\n", parser.state, &parser.text[parser.current]);
  79. }
  80.  
  81. /*
  82.  * Local variables:
  83.  * tab-width: 4
  84.  * c-basic-offset: 4
  85.  * End:
  86.  */
  87.  
  88.